//
//  HRFollowRootViewController.m
//  Hear
//
//  Created by mac on 2017/8/10.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRFollowRootViewController.h"

#import "HRFollowListViewController.h"
#import "HRFollowTopView.h"
#import "HRUserViewModel.h"
@interface HRFollowRootViewController ()
//@property (nonatomic, strong) XXPageTabView *pageTabView;
//@property (nonatomic, strong)HRSegmentView *segmentView;
@property(nonatomic, strong)HRFollowTopView *topView;

@property(nonatomic, strong)HRFollowListViewController *mutualVC;
@property(nonatomic, strong)HRFollowListViewController *myFollowVC;
@property(nonatomic, strong)HRFollowListViewController *tofollowVC;
@property(nonatomic, strong)HRUserViewModel *userViewModel;
@property(nonatomic, copy)NSString *FriendsCount;

@property(nonatomic, copy)NSString *FollowsCount;
@property(nonatomic, copy)NSString *FansCount;

@end

@implementation HRFollowRootViewController
#pragma mark - Get and Set
- (HRUserViewModel *)userViewModel{
    if (_userViewModel == nil) {
        _userViewModel = [[HRUserViewModel alloc] init];
    }
    return _userViewModel;
}

- (HRFollowTopView *)topView{
    if (_topView == nil) {
        WeakSelf
        _topView = [[HRFollowTopView alloc] initWithFrame:CGRectMake(0, kNavBarHeight, kFullWidth, 55)];
        _topView.cutWithIndexBlock = ^(NSInteger index) {
            [weakSelf cutWithIndex:index];
        };
    }
    return _topView;
}


- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupView];

}

- (void)setupView{
    
    
//    self.navigationItem.titleView = self.segmentView;

    self.title = @"关注列表";
    
//    UIButton *leftButton = [UIButton buttonWithType:0];
//    leftButton.size = CGSizeMake(20, 20);
//    [leftButton setImage:[UIImage imageNamed:@"Back-Arrow"] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
//    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    [self.view addSubview:self.topView];

    
    
    HRFollowListViewController *mutualVC = [HRFollowListViewController new];
    mutualVC.followType = MutualFollowType;
    mutualVC.view.frame = CGRectMake(0, _topView.bottom, kFullWidth, kFullHeight-_topView.bottom);
    
    HRFollowListViewController *myFollowVC = [HRFollowListViewController new];
    myFollowVC.followType = MyFollowType;;
    myFollowVC.view.frame = CGRectMake(0, _topView.bottom, kFullWidth, kFullHeight-_topView.bottom);
    
    HRFollowListViewController *tofollowVC = [HRFollowListViewController new];
    tofollowVC.followType = FollowToMyType;;
    tofollowVC.view.frame = CGRectMake(0, _topView.bottom, kFullWidth, kFullHeight-_topView.bottom);
    
    self.mutualVC = mutualVC;
    self.myFollowVC = myFollowVC;
    self.tofollowVC = tofollowVC;
    
    [self addChildViewController:mutualVC];
    [self addChildViewController:myFollowVC];
    [self addChildViewController:tofollowVC];
    [self.view addSubview:mutualVC.view];
    [self.view addSubview:myFollowVC.view];
    [self.view addSubview:tofollowVC.view];
    
    self.myFollowVC.view.hidden = YES;
    self.tofollowVC.view.hidden = YES;
    
    WeakSelf
    self.mutualVC.deleteCountBlock = ^() {
        [weakSelf.topView showPeopelCount:[self.FriendsCount integerValue]-1 andIndex:0];
    };

    self.myFollowVC.deleteCountBlock = ^() {
        [weakSelf.topView showPeopelCount:[self.FollowsCount integerValue]-1 andIndex:1];

    };

    self.tofollowVC.deleteCountBlock = ^() {
        [weakSelf.topView showPeopelCount:[self.FansCount integerValue]-1 andIndex:2];

    };
    
    [self getUserRelationCount];
}




- (void)cutWithIndex:(NSInteger)index{
    if (index == 0){
        self.mutualVC.view.hidden = NO;
        self.myFollowVC.view.hidden = YES;
        self.tofollowVC.view.hidden = YES;
    }else if (index == 1){
        self.mutualVC.view.hidden = YES;
        self.myFollowVC.view.hidden = NO;
        self.tofollowVC.view.hidden = YES;
    }else if (index == 2){
        self.mutualVC.view.hidden = YES;
        self.myFollowVC.view.hidden = YES;
        self.tofollowVC.view.hidden = NO;
    }
}


- (void)getUserRelationCount{
    WeakSelf
    [self.userViewModel getUserRelationCount:@{@"userLocalId":USERID} isContentDict:^(NSDictionary *contentDict) {
        [self.topView showPeopelCount:[contentDict[@"FriendsCount"] integerValue] andIndex:0];
        [self.topView showPeopelCount:[contentDict[@"FollowsCount"] integerValue] andIndex:1];
        [self.topView showPeopelCount:[contentDict[@"FansCount"] integerValue] andIndex:2];
        
        weakSelf.FriendsCount = contentDict[@"FriendsCount"];
        
        weakSelf.FollowsCount = contentDict[@"FollowsCount"];
        weakSelf.FansCount = contentDict[@"FansCount"];
    }];
}


- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
